﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdaptiveDeNet.RAND;

namespace AdaptiveDeNet.Functions
{
    public class Rastrigin : Function
    {

        private double[] o;

        public Rastrigin(double[] upperBound, double[] lowerBound)
        {
            o = new double[upperBound.Length];

            for (int i = 0; i < o.Length; i++)
            {
                o[i] = StaticRand.NextDouble() * (upperBound[i] - lowerBound[i]) + lowerBound[i];
            }
        }
        #region Function Members

        public double Feval(double[] x)
        {
            double fx = 0;

            double sum1 = 0;

            for (int i = 0; i < x.Length; i++)
            {
                sum1 += ((x[i] - o[i]) * (x[i] - o[i])) - (10 * Math.Cos(2 * Math.PI * (x[i] - o[i])));
            }

            fx = 10 * x.Length + sum1;


            return fx;
        }

        #endregion

        #region Function Members


        public double GetTrueF()
        {
            return this.Feval(this.o);
        }

        #endregion
    }
}
